<template>
  <div class="divBox capital">
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <div class="container">
          <el-form size="small" inline label-width="150px">
            <el-form-item
              :label="$t('timeselection')"
              class="width100 is_Scroll"
              style="display: block"
            >
              <el-radio-group
                v-model="tableFrom.date"
                type="button"
                class="mr20 is_Scroll"
                size="small"
                @change="selectChange(tableFrom.date)"
              >
                <el-radio-button
                  v-for="(item, i) in fromList.fromTxt"
                  :key="i"
                  :label="item.val"
                  >{{ item.text }}</el-radio-button
                >
              </el-radio-group>
              <el-date-picker
                v-model="timeVal"
                value-format="yyyy/MM/dd"
                format="yyyy/MM/dd"
                size="small"
                type="daterange"
                placement="bottom-end"
                :placeholder="$t('customtime')"
                style="width: 250px"
                @change="onchangeTime"
              />
            </el-form-item>
            <div>
              <el-form-item :label="$t('keywords')" class="width100 is_Scroll">
                <el-input
                  v-model="tableFrom.keyword"
                  :placeholder="$t('please17')"
                  class="selWidth mr20"
                />
                <el-button
                  size="small"
                  type="primary"
                  icon="el-icon-search"
                  @click="getList"
                  >{{ $t("search") }}</el-button
                >
                <el-button
                  size="small"
                  type="primary"
                  icon="el-icon-top"
                  @click="exportRecord"
                  >{{ $t("listexport") }}</el-button
                >
                <el-button
                  size="small"
                  type="primary"
                  @click="getExportFileList"
                  >{{ $t("exportrecords") }}</el-button
                >
              </el-form-item>
            </div>
          </el-form>
        </div>
      </div>
      <cards-data :card-lists="cardLists" />
      <el-table
        v-loading="listLoading"
        :data="tableData.data"
        style="width: 100%"
        size="mini"
      >
        <el-table-column :label="$t('ordernumber')" min-width="100">
          <template slot-scope="scope">
            <span v-if="scope.row.financial_type != 'mer_accoubts'">{{
              scope.row.order_sn
            }}</span>
            <span v-else>{{ scope.row.financial_record_sn }}</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="financial_record_sn"
          :label="$t('transactionserialnumber')"
          min-width="100"
        />
        <el-table-column
          prop="create_time"
          :label="$t('transactiontime')"
          min-width="100"
          sortable
        />
        <el-table-column
          prop="user_info"
          :label="$t('informationoftheo')"
          min-width="80"
        />
        <el-table-column :label="$t('transactiontype')" min-width="100">
          <template slot-scope="scope">
            <span>{{ scope.row.financial_type | transactionTypeFilter }}</span>
          </template>
        </el-table-column>
        <el-table-column :label="$t('revenueanamount')" min-width="100">
          <template slot-scope="scope">
            <span>{{
              scope.row.financial_pm === 1
                ? scope.row.number
                : -scope.row.number
            }}</span>
          </template>
        </el-table-column>
        <el-table-column :label="$t('operation')" min-width="80" fixed="right">
          <template slot-scope="scope">
            <router-link
              v-if="scope.row.financial_type == 'mer_accoubts'"
              :to="{
                path:
                  `${roterPre}` +
                  '/accounts/reconciliation?reconciliation_id=' +
                  scope.row.order_id
              }"
            >
              <el-button type="text" size="small" class="mr10">{{
                $t("details")
              }}</el-button>
            </router-link>
            <router-link
              v-else-if="
                scope.row.financial_type == 'order' ||
                  scope.row.financial_type == 'brokerage_one' ||
                  scope.row.financial_type == 'brokerage_two'
              "
              :to="{
                path:
                  `${roterPre}` + '/order/list?order_sn=' + scope.row.order_sn
              }"
            >
              <el-button type="text" size="small" class="mr10">{{
                $t("details")
              }}</el-button>
            </router-link>
            <router-link
              v-else
              :to="{
                path:
                  `${roterPre}` +
                  '/order/refund?refund_order_sn=' +
                  scope.row.order_sn
              }"
            >
              <el-button type="text" size="small" class="mr10">{{
                $t("details")
              }}</el-button>
            </router-link>
          </template>
        </el-table-column>
      </el-table>
      <div class="block">
        <el-pagination
          :page-sizes="[20, 40, 60, 80]"
          :page-size="tableFrom.limit"
          :current-page="tableFrom.page"
          layout="total, sizes, prev, pager, next, jumper"
          :total="tableData.total"
          @size-change="handleSizeChange"
          @current-change="pageChange"
        />
      </div>
    </el-card>
    <!--导出订单列表-->
    <file-list ref="exportList" />
  </div>
</template>

<script>
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者，助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2021 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件，未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
import {
  capitalFlowLstApi,
  capitalFlowExportApi,
  getStatisticsApi
} from "@/api/accounts";
import fileList from "@/components/exportFile/fileList";
import { roterPre } from "@/settings";
import cardsData from "@/components/cards/index";

export default {
  components: { fileList, cardsData },
  data() {
    return {
      tableData: {
        data: [],
        total: 0
      },
      roterPre: roterPre,
      listLoading: true,
      tableFrom: {
        keyword: "",
        date: "",
        page: 1,
        limit: 20
      },
      timeVal: [],
      fromList: {
        title: this.$t("selectionperiod"),
        custom: true,
        fromTxt: [
          { text: this.$t("all"), val: "" },
          { text: this.$t("today"), val: "today" },
          { text: this.$t("yesterday"), val: "yesterday" },
          { text: this.$t("last7days"), val: "lately7" },
          { text: this.$t("last30days"), val: "lately30" },
          { text: this.$t("thismonth"), val: "month" },
          { text: this.$t("thisyear"), val: "year" }
        ]
      },
      selectionList: [],
      ids: "",
      tableFromLog: {
        page: 1,
        limit: 10
      },
      tableDataLog: {
        data: [],
        total: 0
      },
      LogLoading: false,
      dialogVisible: false,
      evaluationStatusList: [
        { value: 1, label: this.$t("replied") },
        { value: 0, label: this.$t("noreply") }
      ],
      cardLists: [],
      orderDatalist: null
    };
  },
  mounted() {
    this.getList();
    this.getStatisticalData();
  },
  methods: {
    // 选择时间
    selectChange(tab) {
      this.tableFrom.date = tab;
      this.timeVal = [];
      this.getList();
      this.getStatisticalData();
    },
    // 具体日期
    onchangeTime(e) {
      this.timeVal = e;
      this.tableFrom.date = e ? this.timeVal.join("-") : "";
      this.getList();
      this.getStatisticalData();
    },
    // 获取统计数据
    getStatisticalData() {
      getStatisticsApi({ date: this.tableFrom.date })
        .then(res => {
          this.cardLists = res.data;
        })
        .catch(res => {
          this.$message.error(res.message);
        });
    },
    // 导出
    exportRecord() {
      capitalFlowExportApi(this.tableFrom)
        .then(res => {
          const h = this.$createElement;
          this.$msgbox({
            title: this.$t("tips"),
            message: h("p", null, [
              h("span", null, this.$t("please71")),
              h("span", { style: "color: teal" }, this.$t("exportrecords")),
              h("span", null, this.$t("see"))
            ]),
            confirmButtonText: this.$t("igotit")
          }).then(action => {});
        })
        .catch(res => {
          this.$message.error(res.message);
        });
    },
    // 导出列表
    getExportFileList() {
      this.$refs.exportList.exportFileList();
    },
    // 列表
    getList() {
      this.listLoading = true;
      capitalFlowLstApi(this.tableFrom)
        .then(res => {
          this.tableData.data = res.data.list;
          this.tableData.total = res.data.count;
          this.listLoading = false;
        })
        .catch(res => {
          this.$message.error(res.message);
          this.listLoading = false;
        });
    },
    pageChange(page) {
      this.tableFrom.page = page;
      this.getList();
    },
    handleSizeChange(val) {
      this.tableFrom.limit = val;
      this.getList();
    }
  }
};
</script>

<style lang="scss" scoped>
.selWidth {
  width: 300px;
}
.el-dropdown-link {
  cursor: pointer;
  color: #409eff;
  font-size: 12px;
}
.el-icon-arrow-down {
  font-size: 12px;
}
.tabBox_tit {
  width: 60%;
  font-size: 12px !important;
  margin: 0 2px 0 10px;
  letter-spacing: 1px;
  padding: 5px 0;
  box-sizing: border-box;
}
.mt20 {
  margin-top: 20px;
}
.demo-image__preview {
  position: relative;
  padding-left: 40px;
}
.demo-image__preview .el-image,
.el-image__error {
  position: absolute;
  left: 0;
}
.maxw180 {
  display: inline-block;
  max-width: 180px;
}
</style>
